<?php
 if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Reportuser extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
//        $this->checkLevel1();
        $this->data['controller'] = 'reportuser';   
        $this->load->model('Mreportuser');
        $this->load->model('Mproject');
         
    }
    
    public function listProject()
    {
    
        $this->load->library('pagination');
        $config['per_page'] = $this->data['_per_page'] = 4;
        $this->data['page'] = $this->data['page_current'] = $this->getParamUri(2,1);
        $offset = (($this->getParamUri(2,1) - 1) * $config['per_page']) > 0 ? (($this->getParamUri(2,1) - 1) * $config['per_page']) : 0;
        $data = $this->Mreportuser->getListProject($config['per_page'],$offset);
        $config['base_url'] = base_url($this->uri->segment(1).'/');
        $config['total_rows'] = $data['count'];
        $config['uri_segment'] = 2;
        $config['uri_segment_page'] = $this->getParamUri(2,1);
        $config['suffix'] = '.html';
        $config['use_page_numbers'] = TRUE;
        $this->pagination->initialize($config);
        $this->data['data'] = $data['data'];
        $this->data['user_report']=$data['user'];
        $this->data['action'] = __FUNCTION__;
        $this->load->view('template/layout', $this->data);
    }
    
    public function listModule()
    {
        $id=$this->getParamString("id");   //id Project
        if($this->session->userdata("level") == 1)   //Nếu là admin lấy thêm tham số user id
        {
            $this->data['uid']=$this->getParamString("us");
        }
        $this->load->model('Mproject');
//        $this->data['data'] = $this->Mproject->getProjectDetail($id);
        $this->data['data'] = $this->Mreportuser->getProjectDetail($id);
        $this->data['comment'] = $this->Mproject->getCommentP($id);
        $this->data['process'] = $this->Mreportuser->getProcess($id);
        $this->data['action'] = 'listModule';
        $this->load->view('template/layout', $this->data);
    }
    
    public function sendMail()
    {
        if($this->session->userdata("level") !=  1) //Không phải admin
        {
            redirect("");
        }
        $user_id=$this->getParamString("us");
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            
            $this->load->library('form_validation');
            $this->form_validation->set_rules('subject_email', 'Chủ đề', 'required');
            $this->form_validation->set_rules('content', 'Nội dung', 'required');
            $this->form_validation->set_rules('user', 'Người nhận email', 'required|valid_email');
            if ($this->form_validation->run() === TRUE) {
                $run = $this->Mreportuser->sendMail();
                echo "<script type = 'text/javascript'>alert('Gửi email thành công !');window.location.href='".  site_url()."/"."report-user?us=".$this->getParamString("us")."';</script>";
            }
        }
        $this->data['user']=$this->Mreportuser->getUserDetail($user_id);
        $this->data['action'] = 'sendMail';
        $this->load->view('template/layout', $this->data);
    }
    
    




}
